<template>
    <div>
        <navBar v-on="$listeners" v-bind="$attrs" />
        <LayoutDrag :dragBtnFlag="true">
            <template v-slot:left-content>
                <list class="left_content" v-on="$listeners" v-bind="$attrs" :option="option" />
            </template>
            <template v-slot:right-content>
                <detail class="right_content" v-on="$listeners" v-bind="$attrs" :option="option" @startDraw="startDraw"
                    @updateDraw="updateDraw" />
            </template>
        </LayoutDrag>
    </div>
</template>

<script>
import list from './list.vue'
import detail from './detail'
import { startRingGraphDraw } from '@/api/ringGraph'
export default {
    components: {
        list, detail
    },
    name: 'GenescloudUiIndex',

    data() {
        return {
            option: {},
            queryParams: {
                cloudPictrueCode: null, //图
                taskName: null,    //任务
                sessionId: null,     //链接Id
                routeParams: null,
                chartList: null,
                fileList: null,
            }
        };
    },

    mounted() {

    },

    methods: {
        startDraw(item) {
            this.queryParams.fileList = item
        },
        async updateDraw(item) {
            let routeParams = this.$router.history.current.matched.reduce((pre, item, index) => {
                pre = pre + item.meta.title + ','
                return pre
            }, '')
            let obj = new Date;
            //获取年月日，时分秒
            let a = obj.getFullYear();
            let b = obj.getMonth() + 1;   //月份从0月开始，所以需要+1
            let c = obj.getDate();
            let d = obj.getHours();
            let e = obj.getMinutes();
            let f = obj.getSeconds();
            let num = Math.ceil(Math.random() * 1000);
            if (('' + b).length < 2) b = '0' + b
            if (('' + c).length < 2) c = '0' + c
            if (('' + d).length < 2) d = '0' + d
            if (('' + e).length < 2) e = '0' + e
            if (('' + f).length < 2) f = '0' + f
            let taskName = `${a}${b}${c}${d}${e}${f} - ${num}`
            this.queryParams.sessionId = localStorage.getItem('homeSessionId')
            this.queryParams.routeParams = routeParams
            this.queryParams.cloudPictrueCode = this.$router.history.current.name
            this.queryParams.chartList = item
            this.queryParams.taskName = taskName
            const res = await startRingGraphDraw(this.queryParams)
            if (res.code !== 200) return this.$message.error(res.message)
            console.log(res, 'res');
        }
    },
};
</script>

<style lang="scss" scoped></style>